package com.training.permission.action.chengshu;

import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.training.permission.service.chengshu.IPermissionService;
import com.training.pojo.chengshu.URole;
import com.training.pojo.chengshu.UUser;

public class PermissionUserAction extends ActionSupport{
	private IPermissionService permissionService;
	private List<UUser> listUser;
	private Integer PAGECOUNT = 20;
	private Integer start;
	private Integer end;
	private Integer page = 1;
	private Integer totalPage;
	private Integer countPage;
	private Integer countInfor;
	private String str;  //查询条件
	private Integer i = 0;
	
	public Integer getI() {
		return i;
	}

	public void setI(Integer i) {
		this.i = i;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public String getStr() {
		return str;
	}

	public void setStr(String str) {
		this.str = str;
	}

	public Integer getCountInfor() {
		return countInfor;
	}

	public void setCountInfor(Integer countInfor) {
		this.countInfor = countInfor;
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}

	public Integer getCountPage() {
		return countPage;
	}

	public void setCountPage(Integer countPage) {
		this.countPage = countPage;
	}

	public void setPermissionService(IPermissionService permissionService) {
		this.permissionService = permissionService;
	}

	public List<UUser> getListUser() {
		return listUser;
	}

	public void setListUser(List<UUser> listUser) {
		this.listUser = listUser;
	}

	public IPermissionService getPermissionService() {
		return permissionService;
	}
	public String execute(){
		ActionContext actionContext = ActionContext.getContext();
		if(i==1 && str != null){
			actionContext.getSession().put("keyborduser", str);
		}
		str = (String) actionContext.getSession().get("keyborduser");
		countInfor = permissionService.countUser(str);
		totalPage = ((countInfor%PAGECOUNT)==0)?(countInfor/PAGECOUNT):(countInfor/PAGECOUNT+1);
		
		if(page<1){
			page = 1;   
		}
		if(page>totalPage){
			page = totalPage;
		}
		start = (page-1)*PAGECOUNT + 1;
		//end = start + PAGECOUNT - 1;
		listUser = permissionService.listUser(start, PAGECOUNT,str);
		return SUCCESS;
	}
}
